import * as types from './../constants/ActionTypes';

/*
 * 所有消息列表
 ================================================================*/
export function fetchMessage({start = 1, limit = 50} = {}) {
  return  (dispatch) => {

    let payload = { 
      message_status : 0, 
      message : '加载中',
      start_all : start,
      xxlx : 0
    };

    dispatch({
      payload ,
      type: [types.FETCH_MESSAGES, types.FETCH_MESSAGES_SUCCESS, types.FETCH_MESSAGES_FAILURE],
      meta: {
        fetch: [`message/allforapp?page_no=${start}&page_size=${limit}&xxlx=0`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}

/*
 * 已关注消息列表
 ================================================================*/
export function fetchViewMessage({start = 1, limit = 10} = {}) {
  return  (dispatch) => {

    let payload = { 
      viewmessage_status : 0, 
      message : '加载中',
      start_view: start,
      xxlx : 1
    };

    dispatch({
      payload ,
      type: [types.FETCH_VIEWMESSAGES, types.FETCH_VIEWMESSAGES_SUCCESS, types.FETCH_VIEWMESSAGES_FAILURE],
      meta: {
        fetch: [`message/allforapp?page_no=${start}&page_size=${limit}&xxlx=1`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}

/*
 * 消息列表 - 复位
 ================================================================*/
export function resetMessage(){
  return (dispatch) => {
        let payload = {
            message_status: 0,
            viewmessage_status : 0,
            message: '加载中',
            start_view : 1,
            start_all : 1,
            allmessage : [],
            viewmessage : []
        };
        
        dispatch({
            payload,
            type : types.RESET_MESSAGES
        });
    };
}

/*
 * 消息数量
 ================================================================*/
export function fetchMessageCount() {
  return  (dispatch) => {
    let payload = { 
      message_count_status : 0, 
      message : '加载中' 
    };

    dispatch({
      payload, 
      type: [types.FETCH_MESSAGE_COUNT, types.FETCH_MESSAGE_COUNT_SUCCESS, types.FETCH_MESSAGE_COUNT_FAILURE],
      meta: {
        fetch: [`member/msgnum`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}

/*
 * 清除消息数量
 ================================================================*/
export function resetMessageCount() {
  return (dispatch) => {
        let payload = {
            reset_message_count_status: 1,
            message: '加载中'
        };
        
        dispatch({
            payload,
            type : types.RESET_MESSAGE_COUNT
        });
  };
}

/*
 * 更新消息所属产品关注状态
 ================================================================*/
export function updateMessageProduct(pid, status) {
  return (dispatch) => {
        let payload = {
            update_message_product_status: 1,
            pid : pid,
            status : status,
            message: '加载中'
        };
        
        dispatch({
            payload,
            type : types.UPDATE_MESSAGE_PRODUCT_STATUS
        });
  };
}

/*
 * 消息确认查看
 ================================================================*/
export function confirmMessage(wxmessid) {
  return  (dispatch) => {
    let payload = { 
      message_confirm_status : 0, 
      message : '加载中',
      wxmessid : wxmessid
    };

    dispatch({
      payload, 
      type: [types.CONFIRM_MESSAGE, types.CONFIRM_MESSAGE_SUCCESS, types.CONFIRM_MESSAGE_FAILURE],
      meta: {
        fetch: [`gaoshou/msgconfirm?wxmessid=${wxmessid}`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}


